using System;

namespace PhillyCodeCamp.Infrastructure
{
    public class ExceptionHandler : IExceptionHandler
    {
        private IContextProvider _contextProvider;
        private readonly ILogger _logger;

        public ExceptionHandler() :
            this(DependencyResolver.Resolve<IContextProvider>(),
                 DependencyResolver.Resolve<ILogger>())
        {

        }
        public ExceptionHandler(IContextProvider contextProvider, ILogger logger)
        {
            _contextProvider = contextProvider;
            _logger = logger;
        }

        public void HandleError(Exception ex)
        {
            if (ex != null)
            {
                _logger.Log(ex);
                    
                _contextProvider.Current.Redirect(string.Format("~/errorstatus.aspx"));
            }
        }

    }
}